package com.woniuxy.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 响应字符串统一返回类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseData<T> {
    private Integer code;
    private T data;
    private String msg;

    //成功的方法
    public ResponseData ok(){
        return new ResponseData(ResponseEnum.OK.getCode(),null,ResponseEnum.OK.getMsg());
    }
    /**
     * 查询用的，带参数
     */
    public ResponseData ok(T data){
        return new ResponseData(ResponseEnum.OK.getCode(),data,ResponseEnum.OK.getMsg());
    }
    /**
     * 失败的方法(封装)
     *
     * 传过来枚举对象，获取枚举对象的msg；responseEnum.getMsg()
     */
    public ResponseData fail(ResponseEnum responseEnum){
        return new ResponseData(responseEnum.getCode(), responseEnum.getMsg(),"操作失败");
    }
}
